package com.ray.auth.system.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ray.auth.system.service.ButtonService;
import com.ray.auth.system.service.LogService;
import com.ray.auth.system.table.entity.Button;
import com.ray.auth.system.table.entity.Logs;
import com.ray.common.util.DataGridUtil;
import com.zjhc.flyhong.common.function.operator.LoginUser;
import com.zjhc.flyhong.common.function.operator.PageDto;
import com.zjhc.web.controller.WebController;

@Controller
@RequestMapping("/system/log")
public class LogController extends WebController{
	@Autowired
	private ButtonService buttonService;
	//日志服务
    @Autowired
    private LogService logService;

	/**
	 * 页面跳转
	 * @param menuId
	 * @param request
	 * @param respose
	 * @param modelAndView
	 * @return
	 */
	@RequestMapping(value="view")
	@RequiresPermissions("log:view")
	public ModelAndView view(String menuId,HttpServletRequest request, HttpServletResponse respose,ModelAndView modelAndView){
		LoginUser user =getLoginUser();
		Map<String,List<Button>> buttons=buttonService.queryUserButtonsWithMenu(user, menuId);
		modelAndView.addObject("buttons",buttons);
		modelAndView.setViewName("system/log/view");
		return modelAndView;
	}
	/*
	 * 详情
	 */
	@RequestMapping(value="detailView")
	@RequiresPermissions("log:detail")
	@ResponseBody
	public ModelAndView  detailView(String id,HttpServletRequest request, HttpServletResponse respose,ModelAndView modelAndView){
		LoginUser user=getLoginUser();
		Logs logs=logService.queryLogs(id, user);
		modelAndView.addObject("record", logs);
		modelAndView.setViewName("system/log/detail");
		return modelAndView;
		
	}
	
	/**
	 * 用户查询页面
	 */
	@RequestMapping(value = "query")
	@RequiresPermissions("log:query")
	@ResponseBody
    public ResponseEntity<Map<String,Object>> query(Logs params, HttpServletRequest request, HttpServletResponse respose){
		LoginUser user=getLoginUser();
		PageDto<Logs> page=this.createJQPage(request);
		page=logService.queryLogs(params,page,user);
		return doSuccess(DataGridUtil.dataConvert(page));

	}
}
